package cn.zzuli.springcloud.service.impl;

import cn.zzuli.springcloud.dao.OrderDao;
import cn.zzuli.springcloud.domain.Order;
import cn.zzuli.springcloud.service.AccountService;
import cn.zzuli.springcloud.service.OrderService;
import cn.zzuli.springcloud.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Date: 2020/12/26 18:48
 * @Author: 绯色下午茶
 * @Description:
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;
    @Resource
    private StorageService storageService;
    @Resource
    private AccountService accountService;

    @Override
    public void create(Order order) {
        log.info("***************开始新建订单");
        orderDao.create(order);
        log.info("**************订单微服务开始调用库存，做扣减 count");
        storageService.decrease(order.getProductId(),order.getCount());
        log.info("**************订单微服务开始调用库存，做扣减 count end");

        log.info("**************订单微服务开始调用账户，做扣减 money");
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("**************订单微服务开始调用账户，做扣减 money end");


        log.info("***************修改订单状态开始");
        orderDao.update(order.getUserId(),0);
        log.info("***************修改订单状态结束");

        log.info("***************下订单结束了");

    }
}
